﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace OgilvyOne.SqlServerDAL
{
  public class CommonFun
    {
      public static DataTable GetList(string sTableName, string sFields, string sOrderField, string sWhere, int iPageSize, int iPageIndex, out int iTotalPage, out int iTotalRow)
      {
          IDataParameter[] parameters = {
					new SqlParameter("@TableName", SqlDbType.NVarChar, 4000),
					new SqlParameter("@Fields", SqlDbType.NVarChar, 4000),
					new SqlParameter("@OrderField", SqlDbType.NVarChar,4000),
					new SqlParameter("@sqlWhere", SqlDbType.NVarChar,4000),
					new SqlParameter("@pageSize", SqlDbType.Int),
					new SqlParameter("@pageIndex", SqlDbType.Int),
					new SqlParameter("@TotalPage", SqlDbType.Int),
					new SqlParameter("@TotalRow", SqlDbType.Int),
					};
          parameters[0].Value = sTableName;
          parameters[1].Value = sFields;
          parameters[2].Value = sOrderField;
          parameters[3].Value = sWhere;
          parameters[4].Value = iPageSize;
          parameters[5].Value = iPageIndex;
          parameters[6].Direction = ParameterDirection.Output;
          parameters[7].Direction = ParameterDirection.ReturnValue;

          DataSet ds = SQLHelper.RunProcedure(SQLHelper.CONN_STRING_NON_DTC, "SP_GetRecordByPage", parameters, "ds");
          iTotalPage = Convert.ToInt32(parameters[6].Value);
          iTotalRow = Convert.ToInt32(parameters[7].Value);
          return ds.Tables[0];
      }
    }
}
